package com.example.designpattern.responsibility_two;

import com.example.model.GoodsDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
//import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

/**
 * @author long
 * @date 2024/12/20 14:49
 */
@Service
//@RefreshScope
public class ParamValidatorChainByDynamic {

//    @Value("${validate.sequence}")
    private String validateSequence;

//    @Autowired
    private Map<String,IValidator> validatorMap;

    public void startParamValidate(GoodsDTO dto){

        // 业务校验 校验顺序配置中心配置控制，可以动态调整
        Stream.of(validateSequence.split(","))
                .forEach(name-> validatorMap.get(name).validate(dto));

        // todo 后续的业务处理
    }

}
